package com.masterclient.app.businessmodule.settingmodule.crossborder;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eoner.baselib.widget.navgation.FCNavigationBar;
import com.eoner.middlelib.router.map.FCRouterPath;
import com.masterclient.app.R;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.base.FCBusinessActivity;
import com.masterclient.app.businessmodule.settingmodule.auth.bean.CustomerOcrBean;
import com.masterclient.app.businessmodule.settingmodule.crossborder.adapter.CrossBorderSelectAdapter;
import com.masterclient.app.businessmodule.settingmodule.crossborder.contract.ManageCrossBorderContract;
import com.masterclient.app.businessmodule.settingmodule.crossborder.contract.ManageCrossBorderPresenter;
import com.masterclient.app.businessmodule.settingmodule.crossborder.model.CrossBorderListBean;
import com.masterclient.app.businessmodule.settingmodule.crossborder.model.NewCrossBorderUserMessage;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class CrossBorderNameSelectActivity extends FCBusinessActivity<ManageCrossBorderPresenter> implements ManageCrossBorderContract.View{

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.insert_name)
    TextView insert_name;

    CrossBorderSelectAdapter adapter;
    List<NewCrossBorderUserMessage> list;


    @Override
    protected int requireGetLayoutId() {
        return R.layout.activity_cross_border_name_manage;
    }

    @Override
    protected void requireSetCustomNavigationBar(FCNavigationBar navigationBar) {
        navigationBar.setTitle("我的清关实名信息").setRightBtnText("管理");
    }

    @Override
    protected void requireInitUIAndData(Bundle savedInstanceState) {

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new CrossBorderSelectAdapter();
        recyclerView.setAdapter(adapter);

        View emptyView = View.inflate(mContext,R.layout.null_cross_border_manage,null);

        adapter.bindToRecyclerView(recyclerView);
        adapter.setEmptyView(emptyView);


        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()){
                    case R.id.item:
                        Intent intent = new Intent();
                        intent.putExtra("cross_order_user_message",list.get(position));
                        setResult(104,intent);
                        finish();
                        break;
                }
            }
        });
    }


    @Override
    protected void onNavigationRightClick() {
        ARouter.getInstance().build(FCRouterPath.SETTING_CROSS_BORDER).navigation();
    }

    @Override
    protected void onResume() {
        get_customer_cross_border_list();
        super.onResume();
    }


    @Override
    public void customer_cross_border_list_success(CrossBorderListBean bean) {
        list = new ArrayList<>();
        if(bean.getData() != null && bean.getData().getSh_infos() != null){
            list.addAll(bean.getData().getSh_infos());
        }
        adapter.setNewData(list);
    }

    @Override
    public void customer_cross_border_list_failed(String msg) {

    }

    @Override
    public void showDeleteSuccess() {
        showToast("删除成功");
        get_customer_cross_border_list();
    }

    private void get_customer_cross_border_list() {
        mPresenter.customer_cross_border_list("1");
    }

    @Override
    public void showDeleteFailed() {
        showToast("删除失败");
        get_customer_cross_border_list();
    }

    @Override
    public void changeDefaultSuccess() {
        showToast("设置默认成功");
        get_customer_cross_border_list();
    }

    @Override
    public void changeDefaultfailed() {
        showToast("设置默认失败");
        get_customer_cross_border_list();
    }

    @Override
    public void cross_border_manage_result(String sh_manage_state, String msg) {

    }

    @Override
    public void OnNewOcrResult(CustomerOcrBean bean) {

    }

    @Override
    public void OnNewOcrResultFail(String msg) {

    }

    @Override
    public void onClickPageStateErrorView() {
        super.onClickPageStateErrorView();
        mPresenter.customer_cross_border_list("1");
    }

    @OnClick({R.id.insert_name}) void onClick(View view){
        switch (view.getId()){
            case R.id.insert_name:
                ARouter.getInstance().build(AroutePath.SETTING_UPLOAD_CROSS_BORDER_NAME).navigation();
                break;
        }
    }
}
